package com.mp.approvalreq.servlet.comment;

import com.alibaba.fastjson.JSONObject;
import com.mp.approvalreq.entity.dto.RedPointDTO;
import com.mp.approvalreq.service.RedPointServicePrx;
import com.mp.approvalreq.servlet.AbstractServlet;
import com.mp.user.entity.User;
import com.plusmoney.message.Message;
import com.plusmoney.message.SuccessMsg;
import com.qq.tars.client.util.ServantUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/markMessageUnRead")
public class MarkMessageUnRead extends AbstractServlet {

    private static final Logger logger = LoggerFactory.getLogger(MarkMessageUnRead.class);

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            User user = getReqUser(req);
            String reqBody = getContent(req);
            logger.info("标记消息未读:{}", reqBody);

            RedPointDTO redPointDTO = JSONObject.parseObject(reqBody, RedPointDTO.class);
            redPointDTO.setCompanyInfoId(user.getCompanyInfoId());
            redPointDTO.setContactId(user.getContactId());

            RedPointServicePrx redPointServicePrx = ServantUtils.getObject(RedPointServicePrx.class);
            redPointServicePrx.markMessageUnRead(redPointDTO);

            Message.printJson(resp, SuccessMsg.getDefaultMsg());

        } catch (Throwable throwable) {
            onThrowable(req, resp, throwable);
        }
    }
}
